From e3275354a0efe98e7a570b756fbd95bd99f2e64c Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Sat, 24 May 2008 20:44:49 +0000 Subject: [PATCH] * Add wfRunHook calls where appropriate * Fix handling of file redirects in ApiDelete * Throw an error when a file is undeleted as this is not supported --- includes/api/ApiBlock.php | 1 + includes/api/ApiDelete.php | 11 +++++++++-- includes/api/ApiEditPage.php | 3 +++ includes/api/ApiLogout.php | 4 ++++ includes/api/ApiMove.php | 8 ++++++++ includes/api/ApiUndelete.php | 6 ++++++ 6 files changed, 31 insertions(+), 2 deletions(-) diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php index 3f4d0c9766..f11b4b2435 100644 --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@ -87,6 +87,7 @@ class ApiBlock extends ApiBase { $form->BlockEmail = $params['noemail']; $form->BlockHideName = $params['hidename']; + $userID = $expiry = null; $retval = $form->doBlock($userID, $expiry); if(!empty($retval)) // We don't care about multiple errors, just report one of them diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index 474e756026..aac57f5ee4 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -113,6 +113,8 @@ class ApiDelete extends ApiBase { */ public static function delete(&$article, $token, &$reason = NULL) { + global $wgUser; + $errors = self::getPermissionsError($article->getTitle(), $token); if (count($errors)) return $errors; @@ -124,10 +126,15 @@ class ApiDelete extends ApiBase { if($reason === false) return array(array('cannotdelete')); } + + if (!wfRunHooks('ArticleDelete', array(&$article, &$wgUser, &$reason))) + $this->dieUsageMsg(array('hookaborted')); // Luckily, Article.php provides a reusable delete function that does the hard work for us - if($article->doDeleteArticle($reason)) + if($article->doDeleteArticle($reason)) { + wfRunHooks('ArticleDeleteComplete', array(&$article, &$wgUser, $reason, $article->getId())); return array(); + } return array(array('cannotdelete', $article->mTitle->getPrefixedText())); } @@ -139,7 +146,7 @@ class ApiDelete extends ApiBase { if( $oldimage && !FileDeleteForm::isValidOldSpec($oldimage) ) return array(array('invalidoldimage')); - $file = wfFindFile($title); + $file = wfFindFile($title, false, FileRepo::FIND_IGNORE_REDIRECT); $oldfile = false; if( $oldimage ) diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index c80c84ab47..3413ee2d29 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -69,6 +69,9 @@ class ApiEditPage extends ApiBase { $articleObj = new Article($titleObj); $ep = new EditPage($articleObj); + + if ( !wfRunHooks( 'AlternateEdit', array( &$ep ) ) ) + $this->dieUsageMsg(array('hookaborted')); // EditPage wants to parse its stuff from a WebRequest // That interface kind of sucks, but it's workable diff --git a/includes/api/ApiLogout.php b/includes/api/ApiLogout.php index d0a044825e..e5898a6f01 100644 --- a/includes/api/ApiLogout.php +++ b/includes/api/ApiLogout.php @@ -43,6 +43,10 @@ class ApiLogout extends ApiBase { public function execute() { global $wgUser; $wgUser->logout(); + + // Give extensions to do something after user logout + $injected_html = ''; + wfRunHooks( 'UserLogoutComplete', array(&$wgUser, &$injected_html) ); } public function getAllowedParams() { diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index 4ed5af9867..818f205c41 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -79,6 +79,10 @@ class ApiMove extends ApiBase { // We don't care about multiple errors, just report one of them $this->dieUsageMsg(current($errors)); + $hookErr = null; + if( !wfRunHooks( 'AbortMove', array( $fromTitle, $toTitle, $wgUser, &$hookErr ) ) ) + $this->dieUsageMsg(array('hookaborted', $hookErr)); + $retval = $fromTitle->moveTo($toTitle, true, $params['reason'], !$params['noredirect']); if($retval !== true) $this->dieUsageMsg(array($retval)); @@ -117,6 +121,10 @@ class ApiMove extends ApiBase { $wgUser->removeWatch($toTitle); } $this->getResult()->addValue(null, $this->getModuleName(), $r); + + // This one is a problem as we don't have a special page, but some + // extensions may want to do something when the hook has succeeded. + //wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ; } public function mustBePosted() { return true; } diff --git a/includes/api/ApiUndelete.php b/includes/api/ApiUndelete.php index 9c01a66d83..b9f01c08e4 100644 --- a/includes/api/ApiUndelete.php +++ b/includes/api/ApiUndelete.php @@ -59,6 +59,9 @@ class ApiUndelete extends ApiBase { $titleObj = Title::newFromText($params['title']); if(!$titleObj) $this->dieUsageMsg(array('invalidtitle', $params['title'])); + + if ($titleObj->getNamespace() == NS_IMAGE) + $this->dieUsage('File undeletion is not supported', 'fileundeletionunsupported'); // Convert timestamps if(!is_array($params['timestamps'])) @@ -73,6 +76,9 @@ class ApiUndelete extends ApiBase { if(!is_array($retval)) $this->dieUsageMsg(array('cannotundelete')); + //wfRunHooks( 'FileUndeleteComplete', array( + // $titleObj, $this->mFileVersions, $wgUser, $params['reason']) ); + $info['title'] = $titleObj->getPrefixedText(); $info['revisions'] = $retval[0]; $info['fileversions'] = $retval[1]; -- 2.20.1